<?php
/**
 * link: http://bbs.52jscn.com
 * copyright: Copyright (c) 2018 人人禾匠商城
 * author: zbj
 */

namespace app\plugins\advance\controllers\api;


use app\core\response\ApiCode;
use app\plugins\advance\models\AdvanceSetting;

class ApiController extends \app\controllers\api\ApiController
{
    public function beforeAction($action)
    {
        //权限判断
        $permission = \Yii::$app->branch->childPermission(\Yii::$app->mall->user->adminInfo);
        if (!in_array('advance', $permission)) {
            \Yii::$app->response->data = ['code' => ApiCode::CODE_ERROR, 'msg' => '无商品预售权限'];
            return false;
        }
        //判断预售开关
        $model = AdvanceSetting::findOne(['mall_id' => \Yii::$app->mall->id, 'is_delete' => 0]);
        if (!empty($model) && $model->is_advance == 0) {
            \Yii::$app->response->data = ['code' => ApiCode::CODE_ERROR, 'msg' => '商品预售已关闭'];
            return false;
        }
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }
}
